package com.gift.service.Impl;

import com.gift.common.PaGing;
import com.gift.dao.AccByDeaMapper;
import com.gift.dao.BankByDealtMapper;
import com.gift.dao.DealTableMapper;
import com.gift.pojo.AccByDea;
import com.gift.pojo.BankByDealt;
import com.gift.pojo.DealTable;
import com.gift.service.DataQueryService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/21.
 */

@Service("dataQueryService")
public class DataQueryServiceImpl implements DataQueryService {

    @Resource
    AccByDeaMapper accByDeaMapper;
    @Resource
    BankByDealtMapper bankByDealtMapper;
    @Resource
    DealTableMapper dealTableMapper;


    public Map<String, Object> getMapO(int page, int rows, Map<String, Object> mapO){
        int raa = (page-1) * rows;
        mapO.put("raa",raa);
        mapO.put("rows",rows);
        return mapO;
    }


    @Override
    public PaGing getAllGameAccount(int page, int rows, Map<String, Object> mapO) {
        mapO = getMapO(page,rows,mapO);
        Subject currentUser = SecurityUtils.getSubject();
        Session session=currentUser.getSession();
        session.setAttribute("mapO",mapO);
        int total =accByDeaMapper.getCountAll(mapO);
        List<AccByDea> accByDeaList= accByDeaMapper.getAllBypr(mapO);
        PaGing paGing= new PaGing(total,accByDeaList);
        return paGing;
    }

    @Override
    public PaGing getAllMoneyDeal(int page, int rows, Map<String, Object> mapO) {
        mapO = getMapO(page,rows,mapO);
        Subject currentUser = SecurityUtils.getSubject();
        Session session=currentUser.getSession();
        session.setAttribute("mapO",mapO);
        int total =bankByDealtMapper.getCountAll(mapO);
        List<BankByDealt> bankByDealtList= bankByDealtMapper.getAllBypr(mapO);
        PaGing paGing= new PaGing(total,bankByDealtList);
        return paGing;
    }

    @Override
    public PaGing getAllNormalDeal(int page, int rows, Map<String, Object> mapO) {
        mapO = getMapO(page,rows,mapO);
        Subject currentUser = SecurityUtils.getSubject();
        Session session=currentUser.getSession();
        session.setAttribute("mapO",mapO);
        int total =dealTableMapper.getCountAll(mapO);
        List<DealTable> dealTableList= dealTableMapper.getAllBypr(mapO);
        PaGing paGing= new PaGing(total,dealTableList);
        return paGing;
    }

}
